<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/1
 * Time: 22:03
 */

namespace Lib\Api;


class AgentBelongApi extends UtilsApi {
    private static $modelName = 'AgentBelong';

    /** 获取机构列表
     * @param $where
     * @return mixed
     */
    public static function getAllList($where) {
        $model = M(AgentBelongApi::$modelName);
        $data = $model->where($where)->select();
        return $data;
    }

    /**
     * @param $where
     * @param $left
     * @param string $field
     * @param string $order
     * @param int $page_num
     * @param int $page_size
     * @return mixed
     */
    public static function getUserBelongList($where, $left, $field = "*", $order="", $page_num = 1, $page_size = 15) {
        $model = M();
        $list = $model->table('fs_agent_belong a')
            ->field($field)
            ->join($left)
            ->where($where)
            ->order($order)
            ->page($page_num, $page_size)
            ->select();
        return $list;

    }

    /** 获取用户所有归属
     * @param $where
     * @param $left
     * @param string $field
     * @param string $order
     * @return mixed
     */
    public static function getAllUserBelongList($where, $left="", $field = "*", $order="") {
        $model = M();
        $list = $model->table('fs_agent_belong a')
            ->join($left)
            ->field($field)
            ->where($where)
            ->order($order)
            ->select();
        return $list;
    }

    /** 更具条件获取会员归属机构
     * @param $where
     * @param $left
     * @param string $field
     * @return mixed
     */
    public static function getUserBelongOrgByCondition($where, $left="",  $field="*") {
        $model = M();
        $belongUser = $model->table('fs_agent_belong a')
            ->join($left)
            ->field($field)
            ->where($where)
            ->find();
        return $belongUser;
    }

    public static function saveByCondition($where, $data) {
        $model = M(AgentBelongApi::$modelName);
        return $model->where($where)->save($data);
    }

    /** 添加经纪人归属机构
     * @param $data
     * @return mixed
     */
    public static function add($data) {
        $id = parent::add(AgentBelongApi::$modelName, $data);
        return $id;
    }

    /** 批量添加数据
     * @param $data
     * @return mixed
     */
    public static function addAll($data) {
        $model = M(AgentBelongApi::$modelName);
        return $model->addAll($data);
    }
}